//
//  EditTaskViewController.m
//  MyProject
//
//  Created by Pei on 16/6/24.
//  Copyright © 2016年 Xiaobo Pei. All rights reserved.
//

#import "EditTaskViewController.h"
#import "HTHorizontalSelectionList.h"
#import "ScanViewController.h"
//#import "SelectProjectViewController.h"

@interface EditTaskViewController ()<HTHorizontalSelectionListDelegate, HTHorizontalSelectionListDataSource, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>
{
    HTHorizontalSelectionList *_segementView;
    
    UITableView *_myTable;
    NSArray *_titleArray;
    
    UIView *_footView;
}
@end

@implementation EditTaskViewController


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [[NSNotificationCenter defaultCenter] postNotificationName:Hide_TabBar_Notification object:nil];
}

- (void)viewDidLoad {
    self.navTitle = @"修改检查单";
    [super viewDidLoad];
    
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 22)];
    [rightBtn setTitle:@"保存" forState:UIControlStateNormal];
    [rightBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    rightBtn.titleLabel.font = kAppFont(Home_Big_Size);
    [rightBtn addTarget:self action:@selector(rightBtnAcion) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:rightBtn]];
    
    _titleArray = @[@"检查单信息", @"检查项"];
    
    [self initSelectView];
    [self initTable];
    [self initFootView];
}

#pragma mark ********************** UI **************************
- (void)initSelectView{
    _segementView = [[HTHorizontalSelectionList alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kDeviceWidth, 40.0f)];
    _segementView.delegate = self;
    _segementView.dataSource = self;
    _segementView.autoFillWidth = YES;
    _segementView.font = 14;
    _segementView.sideMargin = 0;
    _segementView.isAdjustBottomLine = YES;
    _segementView.bottomLineMargin = 10.f;
    _segementView.selectionIndicatorColor = kBlueColor;
    [_segementView setSelectedButtonIndex:0];
    [_segementView setTitleColor:kGreenColor forState:UIControlStateNormal];
    [_segementView setBottomTrimColor:kGreenColor];
    [self.view addSubview:_segementView];

}
- (void)initTable{
    _myTable = [[UITableView alloc] init];
    _myTable.frame = CGRectMake(0.0f, _segementView.bottom, kDeviceWidth, kDeviceHeight-NAV_HEIGHT-_segementView.height);
    _myTable.delegate = self;
    _myTable.dataSource = self;
    _myTable.backgroundColor = kRGB(241, 246, 250);
    [self.view addSubview:_myTable];
}
- (void)initFootView{
    _footView = [[UIView alloc] init];
    _footView.frame = CGRectMake(0.0f, 0.0f, kDeviceWidth, 54*3+40);
    _footView.backgroundColor = kWhiteColor;
    _myTable.tableFooterView = _footView;
    
    UIControl *companyControl = [[UIControl alloc] init];
    companyControl.frame = CGRectMake(0.0f, 0.0f, kDeviceWidth, 54.0f);
    [_footView addSubview:companyControl];
    
    UIImageView *arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    arrowImageView.frame = CGRectMake(kDeviceWidth-60.0f-10.0f/2.0f, (companyControl.height-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    [companyControl addSubview:arrowImageView];
    
    UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, (companyControl.height-(Home_Small_Size+2.0f))/2.0f, 60.0f, Home_Small_Size+2.0f)];
    titleLbl.textColor = kRGB(205, 206, 207);
    titleLbl.text = @"检查公司";
    titleLbl.font = kAppFont(Home_Small_Size+2.0f);
    [companyControl addSubview:titleLbl];
    
    UILabel *detailLbl = [[UILabel alloc] initWithFrame:CGRectMake(titleLbl.right, (companyControl.height-(Home_Small_Size))/2.0f, kDeviceWidth-16.0f-60.0f-arrowImageView.width-titleLbl.width-20.0f, Home_Small_Size)];
    detailLbl.textColor = kRGB(100, 99, 104);
    detailLbl.text = @"公司一";
    detailLbl.font = kAppFont(Home_Small_Size);
    detailLbl.textAlignment = NSTextAlignmentRight;
    [companyControl addSubview:detailLbl];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(16.0f, companyControl.height-0.5f, kDeviceWidth-16.0f-60.0f, 0.5f)];
    lineView.backgroundColor = kGreenColor;
    [companyControl addSubview:lineView];
    
    UIControl *projectControl = [[UIControl alloc] init];
    projectControl.frame = CGRectMake(0.0f, companyControl.bottom, kDeviceWidth, 54.0f);
    [projectControl addTarget:self action:@selector(projectControlAction) forControlEvents:UIControlEventTouchUpInside];
    [_footView addSubview:projectControl];
    
    UIImageView *arrowImageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    arrowImageView2.frame = CGRectMake(kDeviceWidth-60.0f-10.0f/2.0f, (projectControl.height-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    [projectControl addSubview:arrowImageView2];
    
    UILabel *titleLbl2 = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, (projectControl.height-(Home_Small_Size+2.0f))/2.0f, 60.0f, Home_Small_Size+2.0f)];
    titleLbl2.textColor = kRGB(205, 206, 207);
    titleLbl2.text = @"检查项目";
    titleLbl2.font = kAppFont(Home_Small_Size+2.0f);
    [projectControl addSubview:titleLbl2];
    
    UILabel *detailLbl2 = [[UILabel alloc] initWithFrame:CGRectMake(titleLbl2.right, (projectControl.height-(Home_Small_Size))/2.0f, kDeviceWidth-16.0f-60.0f-arrowImageView2.width-titleLbl2.width-20.0f, Home_Small_Size)];
    detailLbl2.textColor = kRGB(100, 99, 104);
    detailLbl2.text = @"青岛轨交项目";
    detailLbl2.font = kAppFont(Home_Small_Size);
    detailLbl2.textAlignment = NSTextAlignmentRight;
    [projectControl addSubview:detailLbl2];

    UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(16.0f, projectControl.height-0.5f, kDeviceWidth-16.0f, 0.5f)];
    lineView2.backgroundColor = kGreenColor;
    [projectControl addSubview:lineView2];
    
    UILabel *remarkLbl = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, projectControl.bottom+10.0f, 46.0f, Home_Small_Size+2.0f)];
    remarkLbl.textColor = kRGB(205, 206, 207);
    remarkLbl.text = @"备注：";
    remarkLbl.font = kAppFont(Home_Small_Size+2.0f);
    [_footView addSubview:remarkLbl];
    
    UITextField *remarkField = [[UITextField alloc] init];
    remarkField.frame = CGRectMake(remarkLbl.right+5.0f, remarkLbl.origin.y, kDeviceWidth-16.0f*2.0f-remarkLbl.width, 74.0f);
    remarkField.attributedPlaceholder =[[NSAttributedString alloc] initWithString:@"再次输入需要备注的内容，不超过100字" attributes:@{NSForegroundColorAttributeName: kGreenColor, NSFontAttributeName : kAppFont(Home_Small_Size)}];
    remarkField.font = kAppFont(Home_Small_Size);
    remarkField.delegate = self;
    remarkField.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
    [_footView addSubview:remarkField];
    
    UIView *lineView3 = [[UIView alloc] initWithFrame:CGRectMake(0.0f, _footView.height-0.5f, kDeviceWidth, 0.5f)];
    lineView3.backgroundColor = kGreenColor;
    [_footView addSubview:lineView3];
    
    UIButton *scanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [scanBtn setBackgroundImage:[UIImage imageNamed:@"01saoma"] forState:UIControlStateNormal];
    scanBtn.frame = CGRectMake(kDeviceWidth-16.0f-63.0f/2.0f, (54.0f*2.0f-62.0f/2.0f)/2.0f, 63.0f/2.0f, 62.0f/2.0f);
    [scanBtn addTarget:self action:@selector(scanBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [_footView addSubview:scanBtn];

}
#pragma mark ********************** Action *******************************
- (void)rightBtnAcion
{
    
}

- (void)scanBtnAction{
    ScanViewController *scanVC = [[ScanViewController  alloc] init];
    [self.navigationController pushViewController:scanVC animated:YES];
}

- (void)projectControlAction
{
    //SelectProjectViewController *selectVC = [[SelectProjectViewController alloc] init];
    //selectVC.navTitle = @"选择检查项";
    //[self.navigationController pushViewController:selectVC animated:YES];
}

#pragma mark ********************** Delegate ***************************
#pragma mark  ************************* UITableViewDataSource **************************************
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell_house_History";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
    }
    cell.textLabel.textColor = kRGB(205, 206, 207);
    cell.textLabel.font = kAppFont(Home_Small_Size+2);
    cell.detailTextLabel.font = kAppFont(Home_Small_Size);
    cell.detailTextLabel.textColor = kRGB(100, 99, 104);
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    switch (indexPath.row) {
        case 0:
        {
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.textLabel.text = @"检查单号";
            cell.detailTextLabel.text = @"SJ0000";
        }
            break;
        case 1:
        {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = @"检查类型";
            cell.detailTextLabel.text = @"专项检查";
            
            UIImageView *arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
            arrowImageView.frame = CGRectMake(kDeviceWidth-16.0f-10.0f/2.0f, (54.0f-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
            
            cell.accessoryView = arrowImageView;
        }
            break;
        case 2:
        {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = @"检查日期";
            cell.detailTextLabel.text = @"2015-06-24";
            
            UIImageView *arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
            arrowImageView.frame = CGRectMake(kDeviceWidth-16.0f-10.0f/2.0f, (54.0f-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
            
            cell.accessoryView = arrowImageView;
            
            UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(16.0f, 53.5f, kDeviceWidth-16.0f, 0.5f)];
            lineView.backgroundColor = kGreenColor;
            [cell addSubview:lineView];
        }
            break;
        default:
            break;
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 54;
}


#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

#pragma mark - HTHorizontalSelectionList delegate
- (NSInteger)numberOfItemsInSelectionList:(HTHorizontalSelectionList *)selectionList
{
    return _titleArray.count;
}

- (NSString *)selectionList:(HTHorizontalSelectionList *)selectionList titleForItemWithIndex:(NSInteger)index
{
    return _titleArray[index];
}

- (void)selectionList:(HTHorizontalSelectionList *)selectionList didSelectButtonWithIndex:(NSInteger)index
{
    
}

- (void)selectionList:(HTHorizontalSelectionList *)selectionList didButtonSelectedWithIndex:(NSInteger)index
{
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
